import { editPasswd } from '../pages/login/services/login';
import { message } from 'antd';

export default {
  namespace: 'global',

  state: {
    collapsed: true,
    success: false, // 操作是否成功
  },

  effects: {
    *modifyPassword({ payload }, { call, put }) {
      const response = yield call(editPasswd, payload);
      yield put({ type: 'callbackModifyPassword', response });
    },
  },

  reducers: {
    changeLayoutCollapsed(state, { payload }) {
      return {
        ...state,
        collapsed: payload,
      };
    },

    callbackModifyPassword(st, { response }) {
      const state = st;
      state.success = response.success;
      if (response.success) message.success(response.msg);
      return { ...state };
    },
  },

  subscriptions: {
    setup({ history }) {
      // Subscribe history(url) change, trigger `load` action if pathname is `/`
      return history.listen(({ pathname, search }) => {
        if (typeof window.ga !== 'undefined') {
          window.ga('send', 'pageview', pathname + search);
        }
      });
    },
  },
};
